/**
 * @Description: 谷歌在线地图
 * @Author: xubaoliang
 * @Date: 2022-01-25 09:19:27
 */
import TileLayer from "ol/layer/Tile";
import {OSM} from "ol/source";
import {Map, View} from "ol";

let openStreetMap = {
  /**
   * 初始化百度地图
   * @param elId
   * @param configs
   * @param options
   * @return {Map}
   */
  init: function (elId, configs, options) {
    let mapLayer = new TileLayer({
      source: new OSM()
    });
    let mapApp = new Map({
      target: elId,
      layers: [mapLayer],
      view: new View({
        projection: "EPSG:4326",    //使用这个坐标系
        center: options.center || configs.mapCenter,
        zoom: options.zoom || configs.defaultZoom,
        minZoom: options.minZoom || configs.minZoom,
        maxZoom: options.maxZoom || configs.maxZoom,
        // 设置缩放级别为整数
        constrainResolution: true,
        // 关闭无级别缩放地图
        smoothResolutionConstraint: false
      }),
      controls: []
    });
    return mapApp;
  }
}

export default openStreetMap;
